//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <bsp.h>
#include <mmu.h>
#include <init.h>

EXTERN_C void PrintComPort(const char *szMessage);

STATIC bool_t s_bComPortInited = FALSE;

EXTERN_C DECL_CODEINIT bool_t CDECL InitConsole()
{
    if (!s_bComPortInited) {
        s_bComPortInited = BspSetupComPort(COMPORT_PRINT, NULL);
    }

    return s_bComPortInited;
}

EXTERN_C void CDECL BspWriteConsole(const char *szMessage)
{
    if (NULL == szMessage) return;

    if (!s_bComPortInited) {
        s_bComPortInited = BspSetupComPort(COMPORT_PRINT, NULL);
    }

    if (s_bComPortInited) PrintComPort(szMessage);
}

EXTERN_C void PrintComPort(const char *szMessage)
{
    assert(szMessage);

    for (const char *pc = szMessage; '\0' != *pc; pc++) {
        BspWriteComPort(COMPORT_PRINT, *pc);
    }
}
